﻿//-----------------------------------------------------------------------
// <copyright file="SecurityController.cs" company="CronopioDD">
//     Copyright CronopioDD. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace ProyectoGoya.Controllers
{
    using System.Linq;
    using System.Web.Mvc;
    using ProyectoGoya.Models;

    /// <summary>
    /// SecurityController class
    /// </summary>
    public class SecurityController : Controller
    {
        #region Private Members

        /// <summary>
        /// Entity Framework DB Context
        /// </summary>
        private ProyectoGOYAContext db = new ProyectoGOYAContext();

        #endregion

        #region Public Methods

        /// <summary>
        /// GET: /CheckExistence/123456
        /// </summary>
        /// <param name="dni">DNI to be checked</param>
        /// <returns>Whether the DNI exists or not</returns>
        public JsonResult CheckExistence(string dni)
        {
            var validacionDni = new DniValidationAttribute();
            return this.Json(validacionDni.IsValid(dni), JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region Protected Methods

        /// <summary>
        /// Method for releasing all the resources that it owns
        /// </summary>
        /// <param name="disposing">How it is going to dispose</param>
        protected override void Dispose(bool disposing)
        {
            this.db.Dispose();
            base.Dispose(disposing);
        }

        #endregion
    }
}
